<%@page import="Filter.DAO"%>
<%@page import="java.util.*"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%
    String num ="0";
    String y = "5";
    String sql="select * from Person";
    DAO db =new DAO(); 
    if (request.getParameter("num")!=null && request.getParameter("num")!="")
    {
      num = Integer.toString(Integer.parseInt(request.getParameter("num"))*5);      
    }
    ArrayList<HashMap> rslist= db.query2(sql, new String[]{}, num , y);
    int fin=db.GGININ()/Integer.parseInt(y);
    if(db.GGININ()%Integer.parseInt(y)==0)
        fin--;
%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <table style="border-style: solid ;border-width:5px; width: 300px;">
            <tr>
                <td>id</td>
                <td>username</td>
                <td>tel</td>
                <td>birth</td>
                <td>address</td>
            </tr>                        
                <%
                    for(int i =0;i<rslist.size();i++)
                    {
                        HashMap map =rslist.get(i);
                        out.println("<tr><td>"+map.get("id")+"</td><td>"+map.get("username")+"</td><td>"+map.get("tel")+"</td><td>"+map.get("birthday")+
                        "</td><td>"+map.get("address")+"</tr>");
                    }
                %>            
        </table>
        <form style="width: 300px;" id="GG">
            <%
                    if (!"0".equals(num)){ %>
                    <input type="button" name="up" value="上一頁" onclick="doDel(<%=(Integer.parseInt(num)/5)-1%>)" /> 
            <%}%>            
            <input type="text" id="ININ" name="num" size="5px"/>
            <input type="submit" value="送出"/>
            <%                    
                    if((Integer.parseInt(num)/5) < fin){ %>
            <input type="button" name="down" value="下一頁"  onclick="doDel(<%=(Integer.parseInt(num)/5)+1%>)"/>                                    
            <%}%>    
        </form>
    </body>
    <script>
        function doDel(i){
         document.getElementById("ININ").value = i;
         document.getElementById("GG").submit();            
        }        
    </script>
</html>
